package com.ruoyi.ewem.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.ewem.domain.Ininfo;
import com.ruoyi.ewem.domain.Warehouse;
import com.ruoyi.ewem.mapper.WarehouseMapper;
import com.ruoyi.ewem.service.IninfoService;
import com.ruoyi.ewem.mapper.IninfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author 21037
* @description 针对表【ewem_ininfo(入库记录表)】的数据库操作Service实现
* @createDate 2024-07-27 08:51:53
*/
@Service
public class IninfoServiceImpl extends ServiceImpl<IninfoMapper, Ininfo>
    implements IninfoService{

    @Autowired
    private WarehouseMapper warehouseMapper;

    @Override
    public List<Ininfo> selectIninfoList(Ininfo ininfo) {
        return baseMapper.selectIninfoList(ininfo);
    }

    @Override
    public List<Ininfo> selectByquery(String batchNum) {
        return baseMapper.selectByquery(batchNum);
    }

    /**
     * 签收入库
     *
     * @param inInfo
     * @return
     */
    @Override
    @Transactional
    public int updateIninfo(Ininfo inInfo) {

        // 获取仓库信息
        Warehouse warehouse = warehouseMapper.selectById(inInfo.getWarehouseId());

        // 更新仓库 库存数量
        warehouse.setInventory(warehouse.getInventory()+inInfo.getCount());
        warehouseMapper.updateById(warehouse);

        // 获取入库记录信息
        Ininfo ininfo = baseMapper.selectById(inInfo.getIninfoId());

        // 修改状态为已签收
        ininfo.setStatus("1");

        return baseMapper.updateById(ininfo);
    }
}




